$(document).ready(function(){

///////////////////////// slide Input all  ////////////////

$("#type").change(function(){ 
		var type= document.getElementById("type").value;
		if(type=='footage'){
		$("#input_footage").slideDown("slow");
		$("#input_story").slideUp("slow");
	}else{
		$("#input_story").slideDown("slow");
		$("#input_footage").slideUp("slow");
	}
			

		});	
		




///////////////////////// slide textbox input_file footage and story  //////////////// 		
		
$("#buttonadd").click(function(){ 
		
			var value= document.getElementById("id").value;
			
			for(var i=2;i<=10;i++){	
				if(value==i){
					$("#form"+i).slideDown("normal");
					$("#id").attr('value',i+1);
				}	
			}
	
		});	
		
$("#buttonremove").click(function(){ 
		
			var value= document.getElementById("id").value;
			for(var y=2;y<=10;y++){	
				if(value==y+1){
					document.getElementById('name'+y).value = ' ';
					document.getElementById('file_location'+y).value = ' ';
					document.getElementById('username'+y).value = ' ';
					document.getElementById('hdd'+y).selectedIndex=0;
					$("#form"+y).slideUp("normal");
					$("#id").attr('value',y);
				}
			}
		});
		
////////////////////////  input_file_footage  /////////////////////		

$("#category").change(function(){ 
	
			$("#form1").slideDown("normal");
			$("#buttonadd").slideDown("normal");
			$("#buttonremove").slideDown("normal");

		});	
		
		
		
///////////////////////  Tv_home_view  ///////////////////////		
var click = 0;
$("#input_file").click(function(){ 

if(click == 0){
	$("#input_type").slideDown("normal");
	
click = click+1;
}
else{
	$("#input_type").slideUp("normal");
click = click-1;
}

});
var click1 = 0;
$("#search_file").click(function(){ 

if(click1 == 0){
	$("#search_type").slideDown("normal");
	
click1 = click1+1;
}
else{
	$("#search_type").slideUp("normal");
click1 = click1-1;
}

});


$("#search_type").change(function(){ 
	var type= document.getElementById("search").value;
	if(type=='footage'){
		$("#search_footage").slideDown("normal");
	}else{
		
	}
 });

////////////////////////  check input episode at input_file_story /////////////////// 

$('.check').click(function(){
			
			//alert("abc");
			var episode =  document.getElementById('epi').value;
			if( episode == ""){
				alert("please enter episode");
			}else{
				check_fuc(episode);
			}

		});
	
function check_fuc(episode)
	{
		
		$.ajax({
			type: "GET",
			url : '/file_system_tv/input_file_control/check_epi',
			cache : true,
			data:{
					episode:episode	
				},
			success:function(JsonResult){
			     //alert(JsonResult);
				 if(JsonResult == 1){
				 	$('#chk').attr('src','http://gzdev/file_system_tv/resources/img/true.png');
					$("#form1").slideDown("normal");
					$("#buttonadd").slideDown("fast");
					$("#buttonremove").slideDown("fast");
					$("#submit").slideDown("fast");
					$('#episode').attr('value',episode);
					$('#epi').attr('disabled','disabled');
				 }else{
				 	$('#chk').attr('src','http://gzdev/file_system_tv/resources/img/false.png');
				 }
				}
			});
		}
});